import pickle

a_list = []
b_list = []
c_list = []
d_list = []


def sanitize(time_string):
    if "-" in time_string:
        spliter = "-"
    elif ":" in time_string:
        spliter = ":"
    else:
        return time_string
    (mins, secs) = time_string.split(spliter)
    return mins + '.' + secs


try:
    with open("F:/data/a.txt") as a_file:
        data = a_file.readline()
        a_list = data.strip().split(",")
    with open("F:/data/b.txt") as b_file:
        data = b_file.readline()
        b_list = data.strip().split(",")
    with open("F:/data/c.txt") as c_file:
        data = c_file.readline()
        c_list = data.strip().split(",")
    with open("F:/data/d.txt") as d_file:
        data = d_file.readline()
        d_list = data.strip().split(",")

    # 1.基本处理
    # print(sorted(a_list))
    # print(sorted(b_list))
    # print(sorted(c_list))
    # print(sorted(d_list))

    # clear_a = []
    # clear_b = []
    # clear_c = []
    # clear_d = []
    #
    # for each_tim in a_list:
    #     clear_a.append(sanitize(each_tim))
    # for each_tim in b_list:
    #     clear_b.append(sanitize(each_tim))
    # for each_tim in c_list:
    #     clear_c.append(sanitize(each_tim))
    # for each_tim in d_list:
    #     clear_d.append(sanitize(each_tim))

    # 2.使用列表推导啦简化上面的代码
    # clear_a = sorted([sanitize(t) for t in a_list])
    # clear_b = sorted([sanitize(t) for t in a_list])
    # clear_c = sorted([sanitize(t) for t in a_list])
    # clear_d = sorted([sanitize(t) for t in a_list])

    # print(clear_a)
    # print(clear_b)
    # print(clear_c)
    # print(clear_d)

    # 3
    clear_a = sorted([sanitize(t) for t in a_list])
    clear_b = sorted([sanitize(t) for t in a_list])
    clear_c = sorted([sanitize(t) for t in a_list])
    clear_d = sorted([sanitize(t) for t in a_list])

    print(clear_a)
    print(clear_b)
    print(clear_c)
    print(clear_d)

    unique_a = []
    unique_b = []
    unique_c = []
    unique_d = []
    for each_t in clear_a:
        if each_t not in unique_a:
            unique_a.append(each_t)
    for each_t in clear_b:
        if each_t not in unique_b:
            unique_b.append(each_t)
    for each_t in clear_c:
        if each_t not in unique_c:
            unique_c.append(each_t)
    for each_t in clear_d:
        if each_t not in unique_d:
            unique_d.append(each_t)

    print(unique_a[0:3])
    print(unique_b[0:3])
    print(unique_c[0:3])
    print(unique_d[0:3])

except IOError:
    print("Io Error")
